package com.wondedDream.controller.admin;

import com.wondedDream.model.MockExam;
import com.wondedDream.model.UserMockExamRecord;
import com.wondedDream.service.MockExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController(value = "adminMockExamController")
@RequestMapping("/api/mockExams")
@Api(description = "管理端-模考信息")
public class MockExamController {

    @Autowired
    private MockExamService mockExamService;

    // 创建新的模考
    @PostMapping("/")
    @ApiOperation(value = "创建新的模考")
    public MockExam createMockExam(@RequestBody MockExam exam) {
        return mockExamService.saveMockExam(exam);
    }

    // 根据id删除模考信息
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除模考信息")
    public void deleteMockExam(@PathVariable Integer id) {
        mockExamService.deleteMockExam(id);
    }


    // 根据id修改模考信息
    @PutMapping("/{id}")
    @ApiOperation(value = "根据id修改模考信息")
    public MockExam updateMockExam(@PathVariable Integer id, @RequestBody MockExam mockExam) {
        mockExam.setId(id);
        return mockExamService.updateMockExam(mockExam);
    }


    // 获取模考信息
    @GetMapping("/{id}")
    @ApiOperation(value = "获取模考信息")
    public MockExam getMockExamById(@PathVariable Integer id) {
        return mockExamService.getMockExamById(id);
    }

    // 获取某一分类下的模考列表
    @GetMapping("/byCourse/{categoryId}")
    @ApiOperation(value = "获取某一分类下的模考列表")
    public List<MockExam> getMockExamsByCategoryId(@PathVariable Integer categoryId) {
        return mockExamService.getMockExamsByCategoryId(categoryId);
    }

    // 模考统计接口
    @GetMapping("/mockExams/statistics")
    @ApiOperation(value = "模考统计接口")
    public List<UserMockExamRecord> getMockExamStatistics(@RequestParam(required = false) String timeRange) {
        if (timeRange!= null) {
            return mockExamService.getMockExamStatisticsByTimeRange(timeRange);
        }
        return mockExamService.getMockExamStatistics();
    }
}